<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use chrome\ChromePhp;
use common\Common;
use app\common\model\weixin\LibFansData;
use wechatUtil\Statistics;
use wechatUtil\FansManage;
/**
 * 微信粉丝管理
 * @name WeixinFans.php
 * @package cws
 * @category controller
 * @link http://www.chanekeji.com
 * @author jianfang
 * @version 2.0
 * @copyright CHANGE INC
 * @since 2016-08-13
 */
class  WeixinFans extends AdminController{
	/**
	 * 构造函数
	 */
	function __construct() {
		parent::__construct ();
		error_reporting ( E_ALL & ~ E_NOTICE & ~ E_DEPRECATED & ~ E_STRICT & ~ E_WARNING );
		$this->rightVerify(session('admin'), url("admin/Login/login"));
	
	}
	
	/**
	 * 粉丝列表页面
	 */
	function fansList(){
		
		$this->getSetMenu($this);
		//粉丝列表
		$rawFansList = FansManage::getAllFansList();

		$openIdList = $rawFansList['data']['openid'];
		
		$pageSize = 10;
		$totalPage = ceil($rawFansList['total'] / $pageSize);
		$result = array_chunk($openIdList, $pageSize);	
		session("openIdList",array('total_count' => $rawFansList['total'],'total_page'=> $totalPage,'data'=>$result));
		//分组列表		
		$groups = FansManage::getGroupList();
		session("groupList",$groups['groups']);
		$this->log(__CLASS__, __FUNCTION__, "粉丝列表页面", 1, 'view');
		return $this->fetch("WeixinFans/fansList/fansList");
	}
	
	/**
	 * 分页查询粉丝信息
	 */
	function pagingFans(){
		if(input('param.pageIndex')){
			$pageIndex = input('param.pageIndex');
		}else{
			$pageIndex = 1;
		}
		$openIdList = session('openIdList');
		$uesrInfoList = FansManage::getFansInfoBatch($openIdList['data'][$pageIndex - 1]);
		foreach ($uesrInfoList['user_info_list'] as &$user){
			$groupInfo = FansManage::getGroupById($user['groupid'], session("groupList"));
			$user['groupname'] = $groupInfo['name'];
			$user['groupcount'] = $groupInfo['count'];
		}
		$result = array('page_index'=>$pageIndex,'total_page'=>$openIdList['total_page'],'data'=>$uesrInfoList['user_info_list']);
		echo json_encode(common::errorArray(0, "查询成功", $result));
	}
	
}